<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p></p>
    <input type="file" class="upload">

    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        axios({
            url: "http://hmajax.itheima.net/api/city",
            method: 'get',
            // 拼接路径参数
            params: {
                pname: '四川省'
            }
        }).then(result => {
            document.querySelector('p').innerHTML = result.data.list.join('<br>')
        })


        axios({
            url: "http://hmajax.itheima.net/api/register",
            method: 'post',
            data: {
                username: 'dcj12345',
                password: '123456'
            }
        }).then(result => {
            console.log(result);
        }).catch(error => {

        })


        document.querySelector('.upload').addEventListener('change', e => {
            console.log(e);
            const fd = new FormData()
            fd.append('img', e.target.files[0])
            axios({
                url: "http://hmajax.itheima.net/api/uploadimg",
                method: 'post',
                data: fd
            }).then(result => {
                console.log(result);
            }).catch(error => {

            })
        })

    </script>
</body>

</html>